home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / KEYBOARD.SWG / 0009_Int 09 Support.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  118 lines

  1. UNIT KeyIntr ;  { support for INT 09 16 routines } { Turbo Pascal 5.5+ }
  2.  
  3. INTERFACE
  4.  
  5. Type
  6.    InterruptProcedure = Procedure ;
  7.  
  8. Const
  9.    BiosDataSegment = $40 ;
  10.  
  11. Procedure DisableInterrupts ; Inline( $FA ) ;   { CLI }
  12. Procedure EnableInterrupts ;  Inline( $FB ) ;   { STI }
  13. Procedure CallInterrupt( P : Pointer ) ;
  14.  
  15. Function AltPressed : Boolean ;
  16. Function ControlPressed : Boolean ;
  17. Function ShiftPressed : Boolean ;
  18.  
  19. Procedure EOI ;                      { end of interrupt to 8259 }
  20. Function ReadScanCode : Byte ;       { read keyboard }
  21. Procedure ResetKeyboard ;            { prepare for next key }
  22.                                      { put key in buffer for INT 16 }
  23. Function StoreKey( Scan, Key : Byte ) : Boolean ;
  24.  
  25. IMPLEMENTATION
  26.  
  27. Type
  28.    TwoBytesPtr = ^TwoBytes ;
  29.    TwoBytes =               { one key in the keyboard buffer }
  30.    Record
  31.       KeyCode,
  32.       ScanCode : Byte ;
  33.    End ;
  34.  
  35. Var
  36.    KeyState       : Word Absolute BiosDataSegment:$17 ;
  37.    KeyBufferHead  : Word Absolute BiosDataSegment:$1A ;
  38.    KeyBufferTail  : Word Absolute BiosDataSegment:$1C ;
  39.    KeyBufferStart : Word Absolute BiosDataSegment:$80 ;
  40.    KeyBufferEnd   : Word Absolute BiosDataSegment:$82 ;
  41.  
  42. Procedure CallInterrupt( P : Pointer ) ;
  43. Begin
  44.    Inline( $9C ) ;           { PUSHF }
  45.    InterruptProcedure(P) ;
  46. End ;
  47.  
  48. Function AltPressed : Boolean ;
  49. Begin
  50.    AltPressed := (KeyState and 8) <> 0 ;
  51. End ;
  52.  
  53. Function ControlPressed : Boolean ;
  54. Begin
  55.    ControlPressed := (KeyState and 4) <> 0 ;
  56. End ;
  57.  
  58. Function ShiftPressed : Boolean ;
  59. Begin
  60.    ShiftPressed := (KeyState and 3) <> 0 ;
  61. End ;
  62.  
  63. Procedure EOI ;  { end of interrupt to 8259 interrupt controller }
  64. Begin
  65.    Port[$20] := $20 ;
  66. End ;
  67.  
  68. Function ReadScanCode : Byte ;
  69. Var
  70.    N : Byte ;
  71. Begin
  72.    N := Port[$60] ;     { $FF means keyboard overrun }
  73.    ReadScanCode := N ;
  74. End ;
  75.  
  76. Procedure ResetKeyboard ;      { prepare for next key }
  77. Var
  78.    N : Byte ;
  79. Begin
  80.    N := Port[$61] ;
  81.    Port[$61] := (N or $80) ;
  82.    Port[$61] := N ;
  83. End ;
  84.  
  85. Function StoreKey( Scan, Key : Byte ) : Boolean ;
  86. Var                { put key in buffer that INT 16 reads }
  87.    P : TwoBytesPtr ;
  88.    N : Word ;
  89. Begin
  90.    DisableInterrupts ;
  91.  
  92.    N := KeyBufferTail ;
  93.    P := Ptr( BiosDataSegment, N ) ;
  94.  
  95.    Inc( N, 2 ) ;
  96.    If( N = KeyBufferEnd ) then        { end of the circular buffer }
  97.       N := KeyBufferStart ;
  98.    If( N = KeyBufferHead ) then       { buffer full }
  99.    Begin
  100.       EnableInterrupts ;
  101.       StoreKey := False ;
  102.    End
  103.    Else
  104.    Begin
  105.       P^.KeyCode := Key ;
  106.       P^.ScanCode := Scan ;             { store key in circular buffer }
  107.       KeyBufferTail := N ;              { advance tail pointer }
  108.       EnableInterrupts ;
  109.       StoreKey := True ;
  110.    End ;
  111. End ;
  112.  
  113.  
  114. END.
  115.  
  116.  
  117.  
  118.